package com.fd.dx.web.controllers;

import com.fd.dx.domain.ZP;
import com.fd.dx.service.ZPService;
import com.fd.dx.web.domain.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by lenovo on 2018/2/27.
 */
@Controller
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private ZPService zpService;
    /**
     *
     * @param offset 从第几行取
     * @param limit  一次取多少行
     * @return
     */
    @RequestMapping("/getPage")
    @ResponseBody
    public Page<ZP> getPage(Integer offset, Integer limit){
        Page<ZP> page=new Page<ZP>();
        page.setLimit(limit);
        page.setOffset(offset);
        return zpService.getPage(page);
    }
    @RequestMapping("/parent")
    @ResponseBody
    public ZP parent(Integer pid){
        return zpService.getParentfromPid(pid);
    }
    @RequestMapping("/child")
    @ResponseBody
    public List<ZP> child(Integer pid){
        return zpService.getChildfromPid(pid);
    }
    @RequestMapping("/xd")
    @ResponseBody
    public List<ZP> xd(Integer pid,Integer id){
        Map map=new HashMap();
        map.put("pid",pid);
        map.put("id",id);
        return zpService.getXD(map);
    }
    @RequestMapping("/personFromName")
    @ResponseBody
    public Page<ZP> personFromName(String name,Integer offset, Integer limit){
        Page<ZP> page=new Page<ZP>();
        page.setLimit(10);
        page.setOffset(0);
        return zpService.finePersonFromName(name,page);
    }
    @RequestMapping("/personFromRName")
    @ResponseBody
    public Page<ZP> personFromRName(String rname,Integer offset, Integer limit){
        Page<ZP> page=new Page<ZP>();
        page.setLimit(10);
        page.setOffset(0);
        return zpService.finePersonFromRName(rname,page);
    }
    @RequestMapping("/personFromIDName")
    @ResponseBody
    public Page<ZP> personFromIDName(String idname,Integer offset, Integer limit){
        Page<ZP> page=new Page<ZP>();
        page.setLimit(10);
        page.setOffset(0);
        return zpService.finePersonFromIDName(idname,page);
    }
    @RequestMapping("/txd")
    @ResponseBody
    public List<ZP> txd(Integer pid){
        return zpService.getTXD(pid);
    }
    @RequestMapping("/zpl")
    @ResponseBody
    public List<ZP> zpl(Integer pid){
        return zpService.getZPL(pid);
    }
    @RequestMapping("/hdtt")
    @ResponseBody
    public Integer hdtt(Integer id){
        return zpService.hdtt(id);
    }

}
